package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    NursingLevelService nursingLevelService;


    /**
     * 1 查询所有护理等级
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getAllLevel() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.getAllLevel();
        return success(nursingLevelVos);
    }


    /**
     * 新增
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.addNursingLevel(nursingLevelDto);

        return success();
    }


    /**
     * 条件分页查询
     */
    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理等级名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "护理等级状态", required = false, dataType = "int", paramType = "query"),

    })
    public ResponseResult<PageResponse<NursingLevelVo>> selectByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageResponse<NursingLevelVo> pageInfo = nursingLevelService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }


    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public ResponseResult modify(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.modify(nursingLevelDto);
        return success();
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteLevel(@PathVariable Long id) {
        nursingLevelService.deleteLevel(id);
        return success();
    }

    /**
     * 启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return success();
    }




}
